package com.wy.wuye.utils;

import com.alibaba.fastjson.JSONObject;
import com.wy.wuye.javabean.Repo;

public class RepoFactory {


    public static <T> Repo<T> createRepo(T t, String msg, int code) {
        Repo<T> repo = new Repo<T>();
        repo.setMsg(msg);
        repo.setCode(code);
        repo.setData(t);
        return repo;
    }


    public static String creatRepoString(String msg, int code, KeyValue... value) {

        JSONObject obj = new JSONObject();
        obj.put("msg", msg);

        obj.put("code", code);

        JSONObject jsonObject = new JSONObject();
        obj.put("data", jsonObject);
        for (KeyValue v : value) {
            jsonObject.put(v.getKey(), v.getValue());
        }
        return obj.toJSONString();

    }

    public static Repo<Object> createFileRepo(String msg, int code) {
        Repo<Object> repo = new Repo<Object>();
        repo.setMsg(msg);
        repo.setData(new Object());
        repo.setCode(code);
        return repo;
    }
}
